import java.util.Stack;


// Definition for singly-linked list.

class ListNode {

     int val;

     ListNode next;

     public ListNode(int x) {

         val = x;

         next = null;

     }

     public ListNode insertBefore (ListNode another) {
     	this.next = another;
	return this;
     }

     public String toString() {
	StringBuffer sb = new StringBuffer();
	sb.append(this.val);
        for (ListNode l = this.next; l != null; l = l.next) {
		sb.append("->" + l.val);
	}
	sb.append("\n");
	return sb.toString();
     }
}

public class Solution {

    class Nodes {

        ListNode head;

        ListNode tail;

        Nodes (ListNode h, ListNode t) {

            head = h;

            tail = t;

        }

    };

    
    public static void main (String[] args) {
	if (args.length < 1)
		return;
	ListNode head = new ListNode(Integer.parseInt(args[args.length-1]));
        for (int i = args.length - 2; i >= 0; --i) {
		ListNode l = new ListNode(Integer.parseInt(args[i]));
		head = l.insertBefore(head);
	}

	Solution s = new Solution();
	s.reorderList(head);
	System.out.println(head.toString());
    }

    public void reorderList(ListNode head) {

        if (head == null)

            return;

        if (head.next == null)

            return;

        if (head.next.next == null)

            return;



        Stack<ListNode> stack = new Stack<ListNode>();

        for (ListNode l = head; l != null; l = l.next) {

            stack.push(l);

        }



 //Accepted       

        ListNode h = head;

        ListNode t = stack.pop();

        while (true) {

            if (h == t || h.next == t) {

                break;

            }

            stack.peek().next = null;

            t.next = h.next;

            h.next = t;

            h = h.next.next;

            t = stack.pop();

        }

///


/*//Runtime Error Message:	Line 64: java.lang.StackOverflowError
        Nodes n = reorderListHelper(head, stack);

        head = n.head;
////*/

/*//Time Limit Exceeded

        ListNode tail = head;

        for (; tail.next != null; tail = tail.next)

            ;

            

        reorderListHelper2(head, tail);

*/        

    }

    

    // return the new tail after the reordering, head is the same, so we don't return new head.

    private Nodes reorderListHelper(ListNode head,  Stack<ListNode> stack) {

        ListNode tail = stack.pop();

        

        if (head == tail || head.next == tail)

            return new Nodes(head, tail);



        tail.next = head.next;

        head.next = tail;

        stack.peek().next = null;

        Nodes temp = reorderListHelper(head.next.next, stack);

        return new Nodes(head, temp.tail);
    }

    

    private Nodes reorderListHelper2 (ListNode head, ListNode tail) {

        if (head == tail)

            return new Nodes(head, tail);

        if (head.next == tail)

            return new Nodes(head, tail);

            

        ListNode new_head = head.next;

        ListNode new_tail = head.next;

        for (; new_tail.next != tail; new_tail = new_tail.next)

            ;

        

        new_tail.next = null;

        Nodes temp = reorderListHelper2(new_head, new_tail);

        head.next = tail;

        tail.next = temp.head;

        temp.tail.next = null;

        return new Nodes(head, temp.tail);

    }

}
